package com.shntec.xtask.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;

import com.shntec.bp.common.BaseSQLHelper;
import com.shntec.bp.common.ShntecBaseDAO;
import com.shntec.bp.util.ShntecLogger;

public class XtaskAccountsObject extends ShntecBaseDAO{
	
	private final static String THIS_TABLE_NAME = "xtask_accounts";
	private final static String THIS_PRIMARY_KEY_NAME = "aid";
	
	private Integer aid = null;
	private String userName = null;
	private String passWord = null;
	private Integer grade = null;
	private String name = null;
		
	public XtaskAccountsObject(BaseSQLHelper helper){
		super(helper);
		tableName = THIS_TABLE_NAME;
		primaryKeyName = THIS_PRIMARY_KEY_NAME;
	}

	public Integer getAid() {
		return aid;
	}

	public void setAid(Integer aid) {
		this.aid = aid;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getPassWord() {
		return passWord;
	}

	public void setPassWord(String passWord) {
		this.passWord = passWord;
	}

	public Integer getGrade() {
		return grade;
	}

	public void setGrade(Integer grade) {
		this.grade = grade;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Override
	protected boolean loadResultSet(ResultSet rs) {
		try {
			aid = rs.getInt("aid");
			userName = rs.getString("username");
			passWord = rs.getString("password");
			grade = rs.getInt("grade");
			name = rs.getString("name");
		} catch (SQLException e) {
			ShntecLogger.logger.error("Handle database resultset failed, table name=" + getTableName());
			ShntecLogger.logger.error(e.getMessage());
			return false;
		}
		
		return true;
	}

	@Override
	protected HashMap<String, Object> generateColumnList() {
		HashMap<String, Object> columnList = new HashMap<String, Object>();
		
		columnList.put("aid", aid);
		columnList.put("username", userName);
		columnList.put("password", passWord);
		columnList.put("grade", grade);
		columnList.put("name", name);
		
		return columnList;
	}

	@Override
	protected void updateResultSet(ResultSet rs) throws SQLException {
		
		updateNotAllowNullColumns(rs, "username", userName);
		
		updateNotAllowNullColumns(rs, "password", passWord);
		
		updateNotAllowNullColumns(rs, "grade", grade);
		
		updateNotAllowNullColumns(rs, "name", name);
		
	}
	
	
}
